import java.util.ArrayList;
import java.util.List;

public class Concept {
	private List<String> listattr = new ArrayList<String>();
	private List<String> listobj = new ArrayList<String>();
	private List<Concept> listchild = new ArrayList<Concept>();
	private List<Concept> listparent = new ArrayList<Concept>();
	public boolean POS = false;
	public boolean NEG = false;

	// Object operation
	public void addObjects(List<String> listaddobjs) {
		this.listobj.addAll(listaddobjs);
	}

	// Attribute operation
	public void addAttribute(List<String> listaddattrs) {
		this.listattr.addAll(listaddattrs);
	}

	public int attrCount() {
		return this.listattr.size();
	}

	public String GetAttr(int i) {
		return this.listattr.get(i);
	}

	// Child add,get,count.
	public void addChild(Concept child) {
		if (child != null) {
			this.listchild.add(child);
		}
	}

	public int childcount() {
		return this.listchild.size();
	}

	public Concept getChild(int i) {
		return this.listchild.get(i);
	}

	// Parent add,get,count.
	public void addParent(Concept parent) {
		if (parent != null) {
			this.listparent.add(parent);
		}
	}

	public int parentcount() {
		return this.listparent.size();
	}

	public Concept getParent(int i) {
		return this.listparent.get(i);
	}

	//

	// public List<String> RemoveDuplicateWithOrder(List<String> list) {
	// HashSet<String> set = new HashSet<String>();
	// List<String> newList = new ArrayList<String>();
	// for (Iterator<String> iter = list.iterator(); iter.hasNext();) {
	// String element = iter.next();
	// if (set.add(element))
	// newList.add(element);
	// }
	// return newList;
	// }
	//

	// public void MergeWith( Concept inducedConcept )
	// {
	// listattr.addAll(inducedConcept.listattr);
	// listobj.addAll(inducedConcept.listobj);
	//
	// }
	// public void clearConcept()
	// {
	// listattr.removeAll(listattr);
	// listobj.removeAll(listobj);
	// listchild.removeAll(listchild);
	// listparent.removeAll(listparent);
	// }
	//
	// public boolean Equals( Concept otherConcept )
	// {
	// return (listattr.equals( otherConcept.listattr ) &&
	// listobj.equals( otherConcept.listobj ));
	// }

	// Output attributes and objects
	public String string() {
		String SA = "", SO = "";
		for (String A : listattr) {
			SA = SA + (A + ",");
		}
		for (String O : listobj) {
			SO = SO + (O + ",");
		}
		return SA + "\n" + SO;
	}

	// Child judgment
	public boolean isChild(Concept c) {
		for (int i = 0; i < c.attrCount(); i++) {
			if (!this.listattr.contains(c.GetAttr(i))) {
				return false;
			}
		}
		return true;
	}
	//read string to concept addAttribute(sourceAttr) addObjects(sourceObj) 
	public void AddFormat(String sourceAttr, String sourceObj) {
		String[] array = sourceAttr.split(",");
		List<String> temploc = new ArrayList<String>();
		for (int i = 0; i < array.length; i++) {
			temploc.add(array[i]);
		}
		this.addAttribute(temploc);
		temploc.clear();
		array = sourceObj.split(" ");
		for (int i = 0; i < array.length; i++) {
			temploc.add(array[i]);
		}
		this.addObjects(temploc);
	}

}
